package us.esme.managers
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	public class LogManager
	{
		var file:File;
		var stream:FileStream;
		
		public function LogManager()
		{
			//In future it will be nice to have a configurable Log file(s)
			file = File.applicationStorageDirectory.resolvePath("events.log");
			stream = new FileStream();
		}
		
		public function addLogMessage(message:String):void
		{
			if (message.length != 0)
			{
				openLogFile(FileMode.UPDATE);
				stream.writeUTFBytes(Date.toString() + message);
				closeLogFile();
			}
		}
		
		private function openLogFile(mode:FileMode):void
		{
			stream.open(file, mode);
		}
		
		private function closeLogFile():void
		{
			stream.close();
		}

	}
}